<?php
use	Doctrine\Common\ClassLoader,
	Doctrine\ORM\Tools\Setup,
	Doctrine\ORM\EntityManager;

class CrudusuarioController extends Zend_Controller_Action
{
protected $_em;
    public function init()
    {
        /* Initialize action controller here */
        $registry = Zend_Registry::getInstance();
        $this->_em = $registry->entitymanager;
    }

    private function persistirDatos($unNombre)
    {	$testEntity = new Default_Model_User;
        $testEntity->setName($unNombre);
        $this->_em->persist($testEntity);
        $this->_em->flush();
    }
    public function indexAction()
    {
	$request = $this->getRequest();
        $form    = new Application_Form_Usuario();

	if ($this->getRequest()->isPost()) {
            if ($form->isValid($request->getPost())) {
		$registro = $form->getValues();
                $this->persistirDatos($registro['unnombre']);
                return $this->_helper->redirector('index');
            }
        }
 	$this->view->form = $form;
    }

    public function listarAction()
    {
        $usuarios = $this->_em 
            ->createQuery('select u from Default_Model_User u')
            ->getResult(); 
	$this->view->usuarios = $usuarios;
    }


}



